<template>
  <basic-container>
    <div class="container-body">
      <el-form :inline="true" :model="query" class="demo-form-inline">
        <el-form-item label="邀请人uid">
          <el-input size="small" v-model="query.inviteUserId" placeholder="邀请人uid"></el-input>
        </el-form-item>
        <el-form-item label="邀请人手机号">
          <el-input size="small" v-model="query.inviteUserPhone" placeholder="邀请人手机号"></el-input>
        </el-form-item>
        <el-form-item label="邀请人uid">
          <el-input size="small" v-model="query.invitedUserId" placeholder="被邀请人uid"></el-input>
        </el-form-item>
        <el-form-item label="邀请人手机号">
          <el-input size="small" v-model="query.invitedUserPhone" placeholder="被邀请人手机号"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button size="small" type="primary" icon="el-icon-search" @click="onSearch" :loading="loading">搜索
          </el-button>
          <el-button size="small" icon="el-icon-delete" @click="searchReset" :loading="loading">清空</el-button>
        </el-form-item>
      </el-form>
      <el-table header-row-class-name="container-table-header"
                :data="data" size="small"
                style="width: 100%;margin-bottom: 20px;"
                row-key="inviteId"
                border stripe
                v-loading="loading">
        <el-table-column prop="inviteUserId" label="邀请人uid">
        </el-table-column>
        <el-table-column prop="inviteUserPhone" label="邀请人手机号">
        </el-table-column>
        <el-table-column prop="invitedUserId" label="被邀请人uid">
        </el-table-column>
        <el-table-column prop="invitedUserPhone" label="被邀请人手机号">
        </el-table-column>
        <el-table-column prop="createTime" label="添加时间">
        </el-table-column>
      </el-table>
      <div class="container-page">
        <el-pagination
          @size-change="sizeChange"
          @current-change="currentChange"
          :current-page="page.current"
          :page-sizes="[10, 20, 30, 40, 50, 100]"
          :page-size="10"
          layout="total, sizes, prev, pager, next, jumper"
          :total="page.total">
        </el-pagination>
      </div>
    </div>
  </basic-container>
</template>

<script>
import {fetchList} from "@/api/user/customerInvite";
import {mapGetters} from "vuex";

export default {
  components: {
  },
  data() {
    return {
      importBox: false,
      isEdit: false,
      isView: false,
      viewBox: false,
      formBox: false,
      formTitle: '',
      loading: true,
      query: {},
      form: {},
      page: {
        size: 10,
        current: 1,
        total: 0
      },
      data: [],
      showUploadButton: true,
      fileList: [],
    }
  },
  computed: {
    ...mapGetters(["userInfo", "permissions"])
  },
  created() {
    this.onLoad(this.page);
  },
  methods: {
    // 获取关联题库
    setRelateBook(val) {
      if (val) {
        this.query.bookId = val.bookId;
        this.query.bookName = val.name;
      }
    },
    // 显示题库列表
    showBookDialog() {
      this.bookDialog = true
    },
    // 关闭
    closeBookDialog(val) {
      this.bookDialog = val
    },
    resetForm() {
      this.formBox = false;
      this.isEdit = false;
      this.isView = false;
      this.form = {};
      this.formTitle = '';
      this.$refs['optForm'] && this.$refs['optForm'].resetFields();
      this.viewBox = false;
      this.fileList = [];
      this.qrcodeBox = false;
    },
    onSearch() {
      this.page.current = 1;
      this.onLoad(this.page);
    },
    searchReset() {
      this.query = {};
      this.page.current = 1;
      this.onLoad(this.page);
    },
    searchChange(params, done) {
      this.query = params;
      this.page.current = 1;
      this.onLoad(this.page, params);
      done();
    },
    currentChange(current) {
      this.page.current = current;
      this.onLoad(this.page);
    },
    sizeChange(size) {
      this.page.size = size;
      this.onLoad(this.page);
    },
    onLoad(page, params = {}) {
      this.loading = true;
      fetchList(Object.assign(params, this.query, page)).then(res => {
        this.loading = false;
        const data = res.data.data;
        this.page.total = data.total;
        this.data = data.records;
      });
    },
    handleRemove(file, fileList) {
      this.fileList = fileList;
      this.showUploadButton = true
    },
    handleSuccess(response, file, fileList) {
      this.fileList = fileList;
      if (this.fileList.length >= 1) {
        this.showUploadButton = false
      }
    },
    handlePreview(file) {
      window.open(file.url ? file.url : file.response.data.url)
    },
    beforeRemove(file) {
      return this.$confirm(`确定移除 ${file.name}？`);
    },
  }
};
</script>

<style>
</style>
